package com.ssm.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ssm.pojo.Yong;
import com.ssm.pojo.Record;
import com.ssm.pojo.Book;
import com.ssm.pojo.Page;
import com.ssm.li.PageConstant;
import com.ssm.mapper.Bookmapper;
import com.ssm.service.BookService;

public class BookServiceImpl implements BookService{
    @Autowired
    private Bookmapper bookmapper;

    @Override
    public Page getAllBooks(Book book) {
        // 开始
        Page page = new Page();
        if (book.getCurrentPage() == 0) {
            book.setCurrentPage(PageConstant.PAGE_NUM);
        }
        int start = (book.getCurrentPage() - 1) * PageConstant.PAGE_SIZE;
        book.setStart(start);
        // List集合
        List<Book> list = bookmapper.getAllBooks(book);
        page.setList(list);
        int count = bookmapper.getCount(book);
        int counPage = count / PageConstant.PAGE_SIZE;
        if (count % PageConstant.PAGE_SIZE != 0) {
            counPage++;
        }
        // 总页数
        page.setTotalPage(counPage);
        // 总记录数
        page.setCount(count);
        return page;
    }

    @Override
    public Book getBook(long id) {
        return bookmapper.getBook(id);
    }

    @Override
    public void insertRecord(Record record) {
        bookmapper.insertRecord(record);
    }
    //？？？要留意是管理员还是读者
    @Override
    public List<Record> getRecord(long yongid) {
        return bookmapper.getRecord(yongid);
    }

    @Override
    public List<Record> getBacks(long id) {
        // TODO Auto-generated method stub
        return bookmapper.getBacks(id);
    }

    @Override
    public void updateBacks(long id) {
        // TODO Auto-generated method stub
        bookmapper.updateBacks(id);
    }



    @Override
    public Yong selectYong(Yong yong) {
        // TODO Auto-generated method stub
        return bookmapper.selectYong(yong);
    }
}
